package com.woniuxy.boss.bossassembly.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.woniu.form.AdminForm;
import com.woniu.form.MessageForm;
import com.woniuxy.boss.bossassembly.model.BaAdmin;
import com.woniuxy.boss.bossassembly.model.BaMessage;
import com.woniuxy.boss.bossassembly.dao.BaMessageMapper;
import com.woniuxy.boss.bossassembly.service.IBaMessageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 消息表 服务实现类
 * </p>
 *
 * @author HDC
 * @since 2021-05-24
 */
@Service
@Slf4j
public class BaMessageServiceImpl extends ServiceImpl<BaMessageMapper, BaMessage> implements IBaMessageService {
    @Autowired
    private BaMessageMapper baMessageMapper;
    @Override
    public Integer addMessage(MessageForm messageForm){
        BaMessage baMessage = new BaMessage();
        log.info("Service增加消息{}",messageForm.getType());

        baMessage.setMessageContent(messageForm.getMessageContent());
        baMessage.setSiteId(messageForm.getSiteId());
        baMessage.setType(messageForm.getType());

        return baMessageMapper.insert(baMessage);
    }

    @Override
    public Integer updateMessage(Integer messageId,String examine) {
        log.info("Service修改消息状态{}",examine);
        BaMessage baMessage = baMessageMapper.selectById(messageId);
        baMessage.setExamine(examine);
        UpdateWrapper Wrapper = new UpdateWrapper<>();
        Wrapper.eq("message_id",messageId);
        return baMessageMapper.update(baMessage,Wrapper);
    }

    @Override
    public List<BaMessage> getMessage(String examine){
        List<BaMessage> baMessages = baMessageMapper.getMessage(examine);
        return baMessages;
    }
}
